-
Notifications
You must be signed in to change notification settings - Fork 30
Allow type casting of zero-sized array to any dtype #2123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ffe02f1
to
3292776
Compare
3292776
to
4947f5c
Compare
Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. 🤞 |
Array API standard conformance tests for dpctl=0.21.0dev0=py310h93fe807_59 ran successfully. |
Array API standard conformance tests for dpctl=0.21.0dev0=py310h93fe807_60 ran successfully. |
Array API standard conformance tests for dpctl=0.21.0dev0=py310h93fe807_60 ran successfully. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an interesting consequence of this is as follows:
In [1]: import dpctl.tensor as dpt, dpctl, numpy as np
In [2]: x1 = dpt.ones((0,), dtype="i4")
In [3]: x1.usm_data.nbytes
Out[3]: 4
In [4]: x2 = dpt.ones((0,), dtype="i8")
In [5]: x2.usm_data.nbytes
Out[5]: 8
In [6]: x2 = dpt.usm_ndarray(x1.shape, dtype="i8", buffer=x1)
In [7]: x2.usm_data.nbytes
Out[7]: 4
the underlying representation of a size-0 array is actually an array with a single element, which is generally in the size of the original data type
this is mostly an implementation detail, though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
above note is interesting but overall, doesn't seem important as long as kernels aren't launched on the memory
LGTM
Interesting that NumPy behaves differently and always returns 0 nbytes: x1 = np.ones((0,), dtype="i4")
x1.data.nbytes
# Out: 0
x2 = np.ones((0,), dtype="i8")
x2.data.nbytes
# Out: 0
x2 = np.ndarray(x1.shape, dtype="i8", buffer=x1)
x2.data.nbytes
# Out: 0 Probably dpctl should follow the same here. |
hard to say—underlying tensor |
As per my understanding, it's also a valid pointer in NumPy. It allocates a memory of size 1 in case of zero-space arrays and the same at the deallocation. But in that case it returns My previous comment was mainly if we need to return |
Interesting, I believe CuPy does not, as far as I can tell its memory pointer object is wrapping a nullptr in this case. |
Yes, it seems so for CuPy. |
This PR allows type casting zero-sized
usm_ndarray
to any dtype (including larger ones).